package app.view 
{
	import app.Model;

	import com.bumpslide.ui.LabelButton;

	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**
	 * Button in the Header that changes section
	 * 
	 * @author David Knape
	 */
	public class SectionButton extends LabelButton  
	{

		public var background:MovieClip;

		private var _mySectionNum:uint;		

		private var model:Model = Model.getInstance();

		
		override protected function addChildren():void 
		{
			super.addChildren();
						
			// pull target section num from instance name			
			_mySectionNum = parseInt(name.split('_')[1]);
			
			// get title from model
			label = model.sections[ _mySectionNum ];
			
			// handle clicks
			addEventListener(MouseEvent.CLICK, changeSection);
			
			// update selected state when model tells us to
			model.bind('currentSection', this);
		}

		
		private function changeSection(event:MouseEvent):void 
		{
			model.currentSection = _mySectionNum;
		}

		
		/**
		 * Setter to receive binding from model
		 */
		public function set currentSection( n:int ):void {
			selected = n == _mySectionNum;
		}
	}
}
